<?php

/**
 * sfActionsExt.
 *
 * @package    scar
 * @subpackage actions
 * @author     Jonathan Olger Nieto Lajo <jonathan_nieto@hotmail.com>
 */
abstract class sfActionsExt extends sfActions
{
  const USUARIO_NAMESPACE               = 'usuario';
  const REGISTRO_NAMESPACE              = 'registro';
  const LOG_NAMESPACE                   = 'log';  //LOGIN
  const ERROR_NAMESPACE                 = 'error';
  const GENERAL_NAMESPACE               = 'general';
  const PACIENTE_NAMESPACE              = 'paciente';
  const PERFIL_NAMESPACE                = 'perfil';
  const ESPECIALIDAD_DOCTOR_NAMESPACE   = 'especialidad_doctor';
  const HOSPITAL_NAMESPACE              = 'hospital';
  const ESPECIALIDAD_HOSPITAL_NAMESPACE = 'especialidad_hospital';
  const DOCTOR_NAMESPACE                = 'doctor';
  const TELEFONO_NAMESPACE              = 'telefono';
  const CUERPO_HUMANO_NAMESPACE         = 'cuerpo_humano';
  const PARTE_CUERPO_HUMANO_NAMESPACE   = 'parte_cuerpo_humano';
  const SINTOMA_NAMESPACE               = 'sintoma';
  const ENFERMEDAD_NAMESPACE            = 'enfermedad';
  const DISTRITO_NAMESPACE              = 'distrito';
  const DEPARTAMENTO_NAMESPACE          = 'departamento';
  const PROVINCIA_NAMESPACE             = 'provincia';
  const HISTORIA_CLINICA_NAMESPACE      = 'historia_clinica';
  const DIAGNOSTICO_NAMESPACE           = 'diagnostica';
  const DETALLE_PACIENTE_NAMESPACE      = 'detalle_paciente';
  const PACIENTE_IMAGEN_NAMESPACE       = 'paciente_imagen';
  //para cada modulo se agrega un name_space
  
 
  public function initialize($context, $moduleName, $actionName)
  {
  	parent::initialize($context, $moduleName, $actionName);
  	
  	sfConfig::set('host', 'http://'.$this->getRequest()->getHost());
  }
  
  public static function notifyEmail($subject)
  {
  	$event = sfContext::getInstance()->getEventDispatcher()->notifyUntil
  	         (
  	           new sfEvent($subject, 'actions.send_email')
  	         );
  	         
  	if (!$event->isProcessed())
  	{
  	  throw new sfException(sprintf('Error ocurred while trying to send email named "%s".', $subject));
  	}
  	
  	return $event->getReturnValue();
  }
  
  protected function executeIfExists()
  {
    $args   = func_get_args();
    $method = array_shift($args);
    
    if (method_exists($this, $method))
    {
     return call_user_func_array(array($this, $method), $args);
    }
  }
  
  protected function renderJson($array)
  {
    $this->getResponse()->setContentType('application/json');
    
    return $this->renderText(json_encode($array));
  }
  
  protected function getRouting()
  {
    return sfContext::getInstance()->getRouting();
  }
  
  protected function returnToPrintingSource()
  {
  	$this->route  = $this->getUser()->getFlash('printing_route');
  	switch ($this->route)
  	{
  	  case 'printing_process_koech_labels':
          $this->route = '@printing_process_koech_labels';
          $this->label = 'Regresar a Koech Labels';
          $this->size  = 18;
          break;
  	  case 'printing_process_international_labels':
          $this->route = '@printing_process_international_labels';
          $this->label = 'Regresar a Formularios Internationales';
          $this->size  = 24;
          break;
  	  default:
          $this->route = '@home';
          $this->label = 'Regresar al Home';
          $this->size  = 10;
          break;
  	}
  }
}
